//
//  UIButton+Ext.swift
//  Swift-sina
//
//  Created by gaoyanyun on 16/5/10.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

extension UIButton{
    
    //建立button的便利构造函数
    convenience init(imageName: String, backgroundImageName: String?) {
        self.init()
        
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        
        if let backgroundImageName = backgroundImageName{
            
            setBackgroundImage(UIImage(named: backgroundImageName), forState: .Normal)
            
            setBackgroundImage(UIImage(named: backgroundImageName + "_highlighted"), forState: .Highlighted)
            
        }
        
        sizeToFit()
        
    }
}
